package jianghongxue.dao;

import jianghongxue.entity.JHXEntity;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import java.util.List;
//1
@Component()
public class JHXDao extends HibernateDaoSupport {


    public List<JHXEntity> queryPage(String name) {

        Session session=getSessionFactory().openSession();
        String sql = "select * from 19j06jianghongxue where name like ? ";
        Query query=getSessionFactory().openSession().createSQLQuery(sql);
        query.setParameter(0,  "%" + name + "%");
        //将查询结果转成Map对象的集合
       // query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
       query.setResultTransformer(Transformers.aliasToBean(JHXEntity.class));
        List<JHXEntity> list=  query.list();

        return  list;
    }

    public List<JHXEntity> showAll() {
        Query query=getSessionFactory().openSession().createQuery("from JHXEntity");
        return  query.list();
    }
}
